
package com.jf.cloud.combo.controller.app;

import com.jf.cloud.combo.service.ComboService;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.product.dto.ComboDTO;
import com.jf.cloud.common.product.vo.ComboVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 套餐
 *
 * @author zz
 * @date 2022-08-16 09:18:06
 */
@RestController("appComboController")
@RequestMapping("/ma/combo")
@Tag(name = "app-商品套餐")
public class ComboController {

    @Autowired
    private ComboService comboService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取套餐列表" , description = "分页获取套餐列表")
    public ServerResponseEntity<PageVO<ComboVO>> page(@Valid PageDTO pageDTO, @ParameterObject ComboDTO comboDTO) {
        PageVO<ComboVO> comboPage = comboService.page(pageDTO,comboDTO);
        return ServerResponseEntity.success(comboPage);
    }

    @GetMapping
    @Operation(summary = "获取套餐" , description = "根据comboId获取套餐")
    public ServerResponseEntity<ComboVO> getByComboId(@RequestParam Long comboId) {
        // 用户端系统
        Integer sysType = 0;
        return ServerResponseEntity.success(comboService.getByComboId(comboId,sysType));
    }

    @PostMapping
    @Operation(summary = "保存套餐" , description = "保存套餐")
    public ServerResponseEntity<Void> save(@Valid @RequestBody ComboDTO comboDTO) {
        comboService.save(comboDTO);
        return ServerResponseEntity.success();
    }

    @PostMapping("/pcGetCombo")
    @Operation(summary = "pc端获取套餐信息" , description = "pc端获取套餐信息")
    public ServerResponseEntity<ComboVO> pcGetCombo(@RequestBody ComboDTO comboDTO) {
        return ServerResponseEntity.success(comboService.pcGetCombo(comboDTO,AuthUserContext.get().getSysType()));
    }

//    @PutMapping
//    @Operation(summary = "更新套餐" , description = "更新套餐")
//    public ServerResponseEntity<Void> update(@Valid @RequestBody ComboDTO comboDTO) {
//        Combo combo = mapperFacade.map(comboDTO, Combo.class);
//        comboService.update(comboDTO);
//        return ServerResponseEntity.success();
//    }
//
//    @DeleteMapping
//    @Operation(summary = "删除套餐" , description = "根据套餐id删除套餐")
//    public ServerResponseEntity<Void> delete(@RequestParam Long comboId) {
//        comboService.deleteById(comboId);
//        return ServerResponseEntity.success();
//    }
}
